<?php
/** Facility_list
	* 
	* @package Pharmacy Intervention 
	* @subpackage Controller
	* @category Administrative
	* @author Ray Nowell 
	*/  
class Facility_list extends MY_Controller {

	function Facility_list()
	{
		parent::MY_Controller(MUST_BE_ADMIN);
	}		

	/*
	 * PUBLIC FUNCTIONS (e.g. can be accessed from the browser
	 */
	
	function index()
	{
		define("POPUP_HEIGHT", 230);
		define("POPUP_WIDTH", 800);
		
			
		$data['title'] = COMPANY_NAME.' -- Facility List';
		$data['heading'] = 'Facilities';
	
		$data['additional_javascript_doc_ready_functions'] = get_grid_doc_ready_javascript();
		$data['additional_jquery_javascript'] = get_grid_functions('facility', POPUP_HEIGHT, POPUP_WIDTH);
		
		//removing link..will add java script to do the links
		$data['add_link'] = '<input id="_gridAddTop" type="image" border="0" language="javascript" onclick="return false;" alt="Insert" title="Insert" src="'.base_url().'images/add.png"  style="cursor: pointer;"/>';
		$data['view_link'] = '<input class="GridButton" id="_gridViewTop" type="image" disabled="disabled" border="0" language="javascript" onclick="return false;" alt="View" title="View" src="'.base_url().'images/view_disabled.png"  style="cursor: pointer;"/>';
		$data['copy_link'] = '<input class="GridButton" id="_gridCopyTop" type="image" disabled="disabled" border="0" language="javascript" onclick="return false;" alt="Copy" title="Copy" src="'.base_url().'images/copy_disabled.png"  style="cursor: pointer;"/>';
		$data['delete_link'] = '<input class="GridButton" id="_gridDeleteTop" type="image" disabled="disabled" border="0" language="javascript" onclick="return false;" alt="Delete" title="Delete" src="'.base_url().'images/delete_disabled.png"  style="cursor: pointer;"/>';

		$this->load->library('table');
		$this->table->set_heading('<input type="checkbox" id="_chkMaster">','Facility','Facility URL','Active');
		
		$this->load->model('Facility_model');
		
		//$this->output->enable_profiler(TRUE);	
		$facility_array = $this->Facility_model->get_facility_list();
		
		//loop through the results and checkbox the id
		foreach($facility_array as $row)
		{
			 $java_script_text	= 'popup_edit_single('.$row['facility_id'].');return false;'; //Must do this before replacing text on line below
			 $row['facility_id']= '<input class="GridCheckbox" type="checkbox" name="_chkIntervention'.$row['facility_id'].'" >';
			 $edit_link_atts = array('title' => 'Edit',
										'onclick' => $java_script_text 
									);
			 $row['facility_name'] = anchor('#',$row['facility_name'],$edit_link_atts);
			 $this->table->add_row($row);
		}
		
		$local_table_template = set_table_template();
		$this->table->set_template($local_table_template); 
		$local_table = $this->table->generate();
		$data['facility_list'] = str_replace('<td><input class="GridCheckbox"','<td class="GridCheckboxTd"><input class="GridCheckbox"',$local_table);
		
		//Check flash data to see if there is any text to display to the user 
		$deleted_info = $this->session->flashdata('deleted_info');
		if (!empty($deleted_info))
			$data['deleted_info']	=	$deleted_info;
		
		$data['view'] = 'facility_list_view';
		$this->load->vars($data);
		$this->load->view('master_view', $data);	
			
	}
	
	function delete()
	{
		$this->load->model('Facility_model');
		$ret_val	=	$this->Facility_model->Delete_facility();
		
		if (count($ret_val) > 0)
			$this->session->set_flashdata('deleted_info', $ret_val);
		
		redirect('facility_list');
	}

	function refresh()
	{
		redirect('facility_list');
	}	
}

/* End of file facility_list.php */
/* Location: ./system/application/controllers/facility_list.php */